package com.example.lx5_22.park

import androidx.paging.PagingSource
import androidx.paging.PagingState
import com.example.base.entity.ParkEntityItem
import com.example.base.net.ApiService

class ParkPagingSource(val apiService: ApiService) : PagingSource<Int,ParkEntityItem>() {
    override fun getRefreshKey(state: PagingState<Int, ParkEntityItem>): Int? {
        return null
    }

    override suspend fun load(params: LoadParams<Int>): LoadResult<Int, ParkEntityItem> {
        try {
            val currentPage = params.key ?: 1
            val pick = apiService.getPick(currentPage)
            return LoadResult.Page(pick.data,null,null)
        }catch (e:Exception){
            return LoadResult.Error(e)
        }
    }


}